package com.springboot.template.thread.cycle;

import org.springframework.aop.ThrowsAdvice;

public class StateTest1 {
    public static void main(String[] args) {
        final Object obj = new Object();
        Thread t1 = new Thread(()->{
            synchronized (obj) {
                while (true){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }, "t1");
        t1.start();
        Thread t2 = new Thread(()->{
            synchronized (obj) {
                System.out.println(" hehe " );
            }
        }, "t2");
        t2.start();
        System.out.println("t1.getState() = " + t1.getState());
        System.out.println("t2.getState() = " + t2.getState());
        /**
         * t1.getState() = TIMED_WAITING
         * t2.getState() = BLOCKED
         * BLOCKED表示等待获取锁,WAITING和TIMED_WAITING表示等待其他线程发来通知.
         * TIMED_WAITING线程在等待唤醒，但设置了时限;WAITING线程在无限等待唤醒
         */
    }
}
